@extends("admin.common.admin")

<title>房源管理 - 修改房源属性 - H-ui.admin v3.1</title>
@section("cnt")
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>
        首页
        <span class="c-gray en">&gt;</span>
        修改房源属性
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>


    <article class="page-container">
        @include("admin.common.msg")
        <form class="form form-horizontal" id="form-admin-add" method="post" action="{{ route("admin.fangattr.update",["id" => $fangattr["id"]]) }}">
            @csrf
            @method("PUT")
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>房源属性名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{ $fangattr["name"] }}" placeholder="" id="name" name="name">
                </div>
            </div>

            <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">房源属性级别:</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width:150px;">
                        <select class="select" name="pid" id="pid" size="1">
                                <option @if($fangattr["pid"] == 0 ) selected @endif value="0">==顶级属性==</option>
                            @foreach($data as $item)
                                    <option @if($fangattr["pid"] == $item["id"]) selected @endif value="{{ $item["id"] }}">{{ $item["name"] }}</option>
                            @endforeach
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">房源属性字段名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{ $fangattr["field_name"] }}" placeholder="" id="field_name" name="field_name">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-sm-3"><span class="c-red">*</span>文章封面：</label>
                <div class="formControls col-sm-9">
                    <div id="picker">选择封面文件</div>
                    <input type="hidden" name="icon" value="{{ $fangattr["icon"] }}" id="pic">
                    <img src="{{ $fangattr['icon'] }}" id="showpic" style="width: 100px;">
                    <a onclick="deleteIcon({{ $fangattr['id'] }})">删除</a>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交房源属性&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
@endsection
@section("css")
    <link rel="stylesheet" href="/admin/lib/webuploader/0.1.5/webuploader.css" />
@endsection
@section("js")
    {{--异步文件上传插件js--}}
    <script src="/admin/lib/webuploader/0.1.5/webuploader.min.js"></script>
    <script type="text/javascript">
        const TOKEN = "{{ csrf_token() }}";
        const uploader = WebUploader.create({
            // 选择完图片是否自动上传
            auto: true,
            // swf文件路径
            swf:"/admin/lib/webuploader/0.1.5/uploader.swf",
            // 上传文件处理的后台路由
            server:"{{ route("admin.article.upfile") }}",
            // 选择文件的按钮。可选。
            pick: '#picker',
            // 额外参数
            formData:{
                _token:TOKEN,
                node:"attr"
            },
            // 表单域名称
            fileVal:"file",
            // 压缩
            resize:true,
            // 只能上传图片
            accept:{
                title:"Images",
                extensions:"gif,jpg,jpeg,bmp,png",
                mimeTypes:"image/*"
            }
        });
        // 将返回的数据里面的图片进行页面的展示
        uploader.on("uploadSuccess",function (file, response) {
            $("#pic").val(response.pic);
            $("#showpic").attr("src",response.pic);
        })
        let nenu = 0;
        $("#pid").change(function () {
            nenu = Number($(this).val());
            if( nenu > 0){
                $("#routename").slideDown();
            }else{
                $("#routename").slideUp();
            }
        })
        $(function(){
            $("#form-admin-add").validate({
                rules:{
                    name:{
                        required:true,
                    },
                },
                onkeyup:false,
                success:"valid",
                submitHandler:function(form){
                    form.submit();
                }
            });
        });
        function deleteIcon(id){
            let path = $("#showpic").attr("src");
            $.get("{{ route('admin.fangattr.deletePic') }}",{id,path}).then(res=>{
                $("#showpic").attr("src", "");
                $("#pic").val("");
            });
        }
    </script>
@endsection
